package com.zyg.rm.listener;

import com.aliyuncs.exceptions.ClientException;
import com.zyg.common.utils.SmsUtils;
import com.zyg.rm.config.SmsProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * ------------------------------
 * 作者: LMY
 * 类-功能: XX
 * 创建时间: 2021-11-09 19:06
 * ------------------------------
 **/
@Component
@RabbitListener(queues = "sms")
public class SmsListener {

    @Autowired
    private SmsUtils smsUtils;
    @Autowired
    private SmsProperties smsProperties;

    @RabbitHandler
    public void getMessage(Map<String,String> map) throws ClientException {
        System.out.println("map = " + map);
        //1. 得到参数，再向阿里大于发送消息
        String phone = map.get("phone");
        String signName = map.get("signName");
        String templateCode = map.get("templateCode");
        String templateParam = map.get("templateParam");
        String accessKeyId = smsProperties.getAccessKeyId();
        String accessKeySecret = smsProperties.getAccessKeySecret();
        //2. 发送消息
        smsUtils.sendSms(accessKeyId,accessKeySecret,phone,signName,templateCode,templateParam);
    }




}
